﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace DAO
{
    public class DTP
    {
        public static OleDbConnection ketnoi()
        //OleDbConnection c = new OleDbConnection();
        //public DTP()
        {
            string ckn = "provider=microsoft.jet.oledb.4.0;data source=QLDiem.mdb";
            OleDbConnection c = new OleDbConnection(ckn);
          //  if (c.State == ConnectionState.Closed)
                c.Open();
                return c;
        }
        //Đóng kết nối
        public static void dongketnoi(OleDbConnection c)
        {
            c.Close();
        }

        //Lấy Datatable
        public static DataTable laydulieu(string sql,OleDbConnection c)
        {
            DataTable dt = new DataTable();
            OleDbDataAdapter da = new OleDbDataAdapter(sql, c);
            da.Fill(dt);
            return dt;
        }

        public static bool truyvannonquery(string Sql, OleDbConnection c)
        {
            try
            {
                OleDbCommand cmd = new OleDbCommand(Sql, c);
                cmd.ExecuteNonQuery();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
    }
}
